# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=quantlib
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.7.1
pkgrel=1
pkgdesc="QuantLib - A free/open-source library for quantitative finance (mingw-w64)"
arch=('any')
url='http://quantlib.org'
license=('BSD')
makedepends=("${MINGW_PACKAGE_PREFIX}-boost" "automake" "autoconf" "libtool")
options=('staticlibs' 'strip')
source=(https://downloads.sourceforge.net/project/quantlib/QuantLib/${pkgver}/QuantLib-${pkgver}.tar.gz
        no-undefined.patch)
sha256sums=('b5dc38ae51ad7396ccf7358147753902838ce2870dd6e6a4d829c806db3e0a81'
            'e391fb490928fdf761c7dbb2ca4631d1ccbb092045de50b89fe37a1c5b9787e5')

prepare() {
  cd QuantLib-${pkgver}
  patch -p1 -i ${srcdir}/no-undefined.patch

  ./autogen.sh
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  ../QuantLib-${pkgver}/configure \
    --disable-dependency-tracking \
    --enable-static \
    --enable-shared \
    --enable-intraday \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST}
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
  install -Dm644 ${srcdir}/${_realname}-${pkgver}/LICENSE.TXT "${pkgdir}${MINGW_PREFIX}"/share/licenses/${_realname}/LICENSE
}
